import Dialog from '@vant/weapp/dialog/dialog';
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    mainColor: app.globalData.mainColor,
    baseImgUrl: app.globalData.baseImgUrl,
    indicatorDots: false,
    indicatorColor: '#fff',
    indicatorActiveColor: '#d2ab44',
    autoplay: true,
    interval: 5000,
    duration: 500,
    circular: true,
    bannerList: [],
    isPopup: false,
    dataList: [],
    tempList: [],
    current: 1,
    size: 10,
    stop: false,
    noticeMsg: "",
    lastTime: 0,
  },

  //获取通知
  getNotice() {
    let that = this;
    app.http.get('/avoid/config/notice').then((res) => {
      // console.log('http-res:', JSON.stringify(res));
      that.setData({
        noticeMsg: res.data.configContent
      })
      // console.log('noticeMsg:', this.data.noticeMsg);
    })
  },

  //获取banner列表
  getBannerList() {
    // app.http.get('/gd-fishing/avoid/home/banner/list').then((res) => {
    //   // console.log('http-res:', JSON.stringify(res));
    //   if (res.code != 1) {
    //     return app.errorAlert();
    //   }
    //   const that = this;
    //   that.setData({
    //     bannerList: res.data
    //   });
    //   // console.log("bannerList:", that.data.bannerList);
    // })
    // console.log('http-res:', JSON.stringify(res));
    let res = {
      "code": 1,
      "msg": "成功",
      "data": [{
        "bannerId": 33,
        "sort": 1,
        "address": "/banner/banner4.jpg"
      }, {
        "bannerId": 34,
        "sort": 2,
        "address": "/banner/banner5.jpg"
      }, {
        "bannerId": 35,
        "sort": 3,
        "address": "/banner/banner7.png"
      }],
      "remarks": null
    };
    const that = this;
    that.setData({
      bannerList: res.data
    });
    // console.log("bannerList:", that.data.bannerList);
  },

  //数据列表
  getDataList() {
    const that = this;
    if (that.data.stop) {
      return;
    }
    let params = {
      "current": this.data.current,
      "size": this.data.size
    };
    // app.http.post('/gd-fishing/avoid/home/info/list', params).then((res) => {
    //   // console.log('http-res:', JSON.stringify(res));
    //   if (app.errorAlert(res)) {
    //     return;
    //   }
    //   let records = res.data.records;
    //   if (records.length == 0) {
    //     that.setData({
    //       stop: true
    //     });
    //     that.endHandle();
    //     return;
    //   }
    //   let list = that.data.dataList;
    //   for (let i = 0; i < records.length; i++) {
    //     list.push(records[i]);
    //   }
    //   that.setData({
    //     dataList: list
    //   });
    //   // console.log("dataList:", that.data.dataList);
    // })
    // console.log('http-res:', JSON.stringify(res));
    let res = {
      "code": 1,
      "msg": "成功",
      "data": {
        "records": [{
          "infoId": "1854757326750466050",
          "userId": 8,
          "nickName": "月下蓑衣客",
          "headImg": "/20241115/1731634694721.jpeg",
          "infoContent": "滴水湖又名芦潮湖，位于浦东新区南汇新城镇，距离上海市中心约76公里，是南汇新城的中心湖泊。滴水湖呈正圆形，直径约2.6公里，总面积约5.56平方公里，蓄水量约1620万立方米，最深约6.2米，湖面平如镜，岸边花草香，景色影相连，人在岸边游。类似太湖之景致，加上兔耳岭的高山草甸之美，如同远离城市之喧嚣。湖中还有三个总面积为0.48平方公里的小岛，湖水源自大治河，水质为五类地表水。",
          "localName": "环湖西一路儿童乐园",
          "localAddress": "上海市浦东新区南汇新城镇环湖东一路辅路与环湖南一路辅路交叉口西南方向320米左右",
          "lng": "121.949169",
          "lat": "30.887955",
          "createTime": "2024-11-08 13:26",
          "imgList": ["/20241108/1731043557485.jpg", "/20241108/1731043565616.jpg"],
          "concern": null,
          "collect": null,
          "praise": null
        }, {
          "infoId": "1854757132478693378",
          "userId": 8,
          "nickName": "月下蓑衣客",
          "headImg": "/20241115/1731634694721.jpeg",
          "infoContent": "明珠湖湖水清澈，环境幽雅，自然风光秀美。据检测，明珠湖大气环境质量为国家一级，水质为国家二级，土壤清洁，无污染、无公害。湖面南北长约3500米，东西宽500-700米，最深处负7-8米，可与杭州西湖媲美。明珠湖是上海崇明最大的天然淡水湖泊，原是长江南支的一条支流，上个世纪七十年代经人工筑堤围造而成，现建有二个进出水闸门，以保持与长江的亲缘关系。湖中鱼类资源丰富，路亚的对象鱼种如翘嘴、七星鲈等量多。",
          "localName": "西沙国家湿地公园-听潮平台",
          "localAddress": "上海市崇明区堡湖路西沙国家湿地公园内",
          "lng": "121.236129",
          "lat": "31.720063",
          "createTime": "2024-11-08 13:25",
          "imgList": ["/20241108/1731043518483.jpg"],
          "concern": null,
          "collect": null,
          "praise": null
        }, {
          "infoId": "1854756958373134338",
          "userId": 8,
          "nickName": "月下蓑衣客",
          "headImg": "/20241115/1731634694721.jpeg",
          "infoContent": "长风公园“银锄湖”水域广大，历年未干，湖内既生长着多种野生淡水鱼类，也放养了大量养殖性鱼类，其中不乏有个体巨大的青、草、鲤、鲢、鳙的存在，因此在那里垂钓充满了悬念和刺激，无时无刻都吸引着大批钓鱼爱好者前来垂竿，近年来，由于湖内陆续投放了巨量的大个体鲢、鳙鱼种，钓友钓获甚多，从而使得去长风公园垂钓鲢、鳙渐渐演变成上海钓鱼界一种特别的钓鱼文化，吸引着更多的钓鱼爱好者趋之若骛，百折不回。",
          "localName": "上海长风海洋世界",
          "localAddress": "上海市普陀区大渡河路451号",
          "lng": "121.397027",
          "lat": "31.225171",
          "createTime": "2024-11-08 13:24",
          "imgList": ["/20241108/1731043476727.jpg"],
          "concern": null,
          "collect": null,
          "praise": null
        }, {
          "infoId": "1854756809504702466",
          "userId": 8,
          "nickName": "月下蓑衣客",
          "headImg": "/20241115/1731634694721.jpeg",
          "infoContent": "一场阵雨过后，听说台风被小怪兽收走了，我拿着小鱼竿愉快的去钓鱼，池塘的水更深了，水底石头很多。\n果然，立秋后的水很凉，冰凉冰凉的，我只能选择留下一个鱼漂。\n( ˘•ω•˘ ).｡oஇ",
          "localName": "",
          "localAddress": "",
          "lng": "",
          "lat": "",
          "createTime": "2024-11-08 13:24",
          "imgList": [],
          "concern": null,
          "collect": null,
          "praise": null
        }],
        "total": 4,
        "size": 10,
        "current": 1,
        "pages": 1
      },
      "remarks": null
    };
    let records = res.data.records;
    if (records.length == 0) {
      that.setData({
        stop: true
      });
      that.endHandle();
      return;
    }
    let list = that.data.dataList;
    for (let i = 0; i < records.length; i++) {
      list.push(records[i]);
    }
    that.setData({
      dataList: list
    });
    // console.log("dataList:", that.data.dataList);
  },

  //搜索
  onSearch(event) {
    // console.log("detail:", event.detail);
    app.globalData.search = event.detail;
    wx.switchTab({
      url: '/pages/shop/index'
    })
  },

  //跳转链接
  toBannerUrl(e) {
    // console.log("------>val:", e.currentTarget.dataset.val);
    let banner = e.currentTarget.dataset.val;
    if (banner.bannerUrl == null || banner.bannerUrl.length == 0) {
      return;
    }
    if (banner.urlType == 1) {
      wx.navigateTo({
        url: '/pages/shop/detail/detail?id=' + banner.bannerUrl
      })
    } else if (banner.urlType == 2) {
      wx.navigateTo({
        url: '/pages/news/detail/detail?id=' + banner.bannerUrl
      })
    } else if (banner.urlType == 3) {
      wx.navigateTo({
        url: '/pages/index/show/show?url=' + banner.bannerUrl
      })
    }
  },

  //跳转详情
  toDetail(e) {
    // console.log("------>val:", e.currentTarget.dataset.val);
    if (app.loginAlert()) {
      return;
    }
    wx.navigateTo({
      url: '/pages/info/index?id=' + e.currentTarget.dataset.val.infoId
    })
  },

  //跳转网红
  toHot(e) {
    app.notOpen();
  },

  //跳转商城
  toShop(e) {
    app.notOpen();
  },

  //交流群
  toTalk() {
    wx.navigateTo({
      url: '/pages/talk/index'
    })
  },

  //关于我们
  toWe() {
    wx.navigateTo({
      url: '/pages/introduction/index'
    })
  },

  //点击刷新
  clickRefresh(e) {
    // console.log('---------->time:', e.timeStamp);
    let newTime = e.timeStamp;
    let timeNumber = newTime - this.data.lastTime;
    //两次点击时间小于300毫秒，认为是双击
    if (timeNumber < 300) {
      // console.log('---------->双击:', timeNumber);
      this.refreshData();
    }
    this.setData({
      lastTime: newTime
    });
  },

  //刷新数据
  refreshData() {
    let that = this;
    if (that.data.stop) {
      that.setData({
        current: 0,
        stop: false
      });
      return;
    }
    let list = that.data.dataList.length > 0 ? that.data.dataList : that.data.tempList;
    that.setData({
      current: this.data.current + 1,
      dataList: [],
      tempList: list
    });
    this.getDataList();
  },

  //数据结束时处理(防止刷新按钮导致dataList空值)
  endHandle() {
    let that = this;
    if (that.data.dataList.length == 0) {
      that.setData({
        dataList: that.data.tempList
      });
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.test();
    this.getBannerList();
    this.getDataList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.getNotice();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      current: this.data.current + 1
    });
    this.getDataList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})